import { useCallback, useEffect, useState } from "react";
import { View } from "@tarojs/components";
import { IHeaderBox } from "@/components/index";
import Taro, { useRouter } from "@tarojs/taro";
import { Cell, CellGroup } from "@nutui/nutui-react-taro";
import { getExamDetail } from "@/axios/exam";

import "./index.scss";

interface ExamDetailProps {}

const ExamDetailIndex: React.FC<ExamDetailProps> = () => {
  const {
    params: { id },
  } = useRouter();

  const [examInfo, setExamInfo] = useState<API.ExamResultProps>({
    abstractLevel: "",
    calLevel: "",
    dicLevel: "",
    grammarLevel: "",
    imagineLevel: "",
    infoLevel: "",
    intelName: "",
    matLevel: "",
    natureName: "",
    profession: "",
    reasonLevel: "",
    subInterest: "",
    userName: "",
  });

  const getExamInfo = useCallback(async () => {
    try {
      const result = await getExamDetail(Number(id));
      setExamInfo(result);
    } catch {}
  }, [id]);

  useEffect(() => {
    if (!id) {
      Taro.showToast({
        title: "查看失败!",
        icon: "error",
        complete: () => {
          setTimeout(() => {
            Taro.navigateBack();
          }, 1500);
        },
      });
    }
    getExamInfo();
  }, [getExamInfo, id]);

  return (
    <View className="exma_result_page">
      <View className="info_box">
        <IHeaderBox title="基础信息" />
        <View className="info_box">
          <CellGroup>
            <Cell title="姓名" extra={examInfo.userName} />
            <Cell title="性格类型" extra={examInfo.natureName} />
          </CellGroup>
        </View>
      </View>
      <View className="info_box">
        <IHeaderBox title="测评结果" />
        <View className="info_box">
          <CellGroup>
            <Cell title="多元智能" extra={examInfo.intelName} />
            <Cell title="学科兴趣" extra={examInfo.subInterest} />
            <Cell title="职业兴趣" extra={examInfo.profession} />
          </CellGroup>
        </View>
      </View>
      <View className="info_box">
        <IHeaderBox title="英语能力" />
        <View className="info_box">
          <CellGroup>
            <Cell title="词汇掌握" extra={examInfo.dicLevel} />
            <Cell title="语法基础" extra={examInfo.grammarLevel} />
            <Cell title="信息筛选" extra={examInfo.infoLevel} />
          </CellGroup>
        </View>
      </View>
      <View className="info_box">
        <IHeaderBox title="数学能力" />
        <View className="info_box">
          <CellGroup>
            <Cell title="空间想象" extra={examInfo.imagineLevel} />
            <Cell title="抽象概括" extra={examInfo.abstractLevel} />
            <Cell title="推理论证" extra={examInfo.reasonLevel} />
            <Cell title="运算求解" extra={examInfo.calLevel} />
            <Cell title="资料处理" extra={examInfo.matLevel} />
          </CellGroup>
        </View>
      </View>
    </View>
  );
};

export default ExamDetailIndex;
